<?php
require './common/function.php';
if($_POST){
    //接收页面传过来的参数  订单编号，商品编号，收件信息
    $nids=$_POST['nids'];
    $pids=$_POST['pids'];
    $receiverAddress=$_POST['receiverAddress'];
    $receiverName=$_POST['receiverName'];
    $receiverPhone=$_POST['receiverPhone'];
    //根据订单编号更新订单表  订单状态，收件信息
    $flog=false;
    foreach ($nids as $k=>$nid){
        $sql="UPDATE t_order SET receiverAddress = '$receiverAddress',receiverName='$receiverName',receiverPhone='$receiverPhone',paystate=0 where id='$nid'";
        $upOrder = getMySql($sql,'更新订单表失败');
        if($upOrder){
            //拆分订单号
            $pid=explode('_',$nid);
            $proId=$pid[0];
            //根据商品编号去更新购物车表   订单编号
            if($pids[$k]==$proId){
                $sql2="update t_product_order set oid='$nid' where pid='$proId' and oid is null";
                $upProOrd = getMySql($sql,'更新购物表失败');
                if($upProOrd){
                    $flog=true;
                }else{
                    $flog=false;
                }
            }
        }else{
            $flog=false;
        }
    }
    if($flog){
        require './html/success.html';
        exit;
    }else{
        require './html/addOrder.html';
        exit;
    }
}
